﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Sky.Web.Models;

namespace Sky.Web.Controllers
{
    public class HomeController : Controller
    {
        StoreEntities storeDB = new StoreEntities();
        
        //
        // GET: /Home/

        public ActionResult Index()
        {
            var album = GetTopSellingAlbum(5);
            return View(album);
        }

        /// <summary>
        /// 获得热销专辑
        /// </summary>
        /// <param name="count"></param>
        /// <returns></returns>
        public List<Album> GetTopSellingAlbum(int count)
        {
            return storeDB.Albums
                .OrderByDescending(a => a.OrderDetails.Count()).Take(count).ToList();
        }
    }
}
